/*
 * All content copyright http://www.j2eefast.com, unless
 * otherwise indicated. All rights reserved.
 * No deletion without permission
 */
package com.j2eefast.web.service;

import com.j2eefast.web.entity.ItemSkuPropEntity;
import com.j2eefast.web.mapper.ItemSkuPropMapper;
import com.j2eefast.common.core.page.Query;
import com.j2eefast.common.core.utils.PageUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.j2eefast.common.core.utils.ToolUtil;
import com.j2eefast.framework.utils.Constant;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;
import java.util.Map;
import java.util.List;
import java.util.Arrays;

/**
 * 【请填写功能名称】Service接口
 * @author: ZhouZhou
 * @date 2021-06-11 10:29:57
 */
@Service
public class ItemSkuPropService extends ServiceImpl<ItemSkuPropMapper,ItemSkuPropEntity> {

	@Resource
	private ItemSkuPropMapper itemSkuPropMapper;

	/**
	 * mybaitis-plus 单表页面分页查询
     */
	public PageUtil findPage(Map<String, Object> params) {
		QueryWrapper<ItemSkuPropEntity> queryWrapper = new QueryWrapper<ItemSkuPropEntity>();
		String addTime = (String) params.get("addTime");
        queryWrapper.eq(ToolUtil.isNotEmpty(addTime), "add_time", addTime);
		String deleted = (String) params.get("deleted");
        queryWrapper.eq(ToolUtil.isNotEmpty(deleted), "deleted", deleted);
		String isSearch = (String) params.get("isSearch");
        queryWrapper.eq(ToolUtil.isNotEmpty(isSearch), "is_search", isSearch);
		String propId = (String) params.get("propId");
        queryWrapper.eq(ToolUtil.isNotEmpty(propId), "prop_id", propId);
		String propName = (String) params.get("propName");
        queryWrapper.like(ToolUtil.isNotEmpty(propName), "prop_name", propName);
		String propValue = (String) params.get("propValue");
        queryWrapper.eq(ToolUtil.isNotEmpty(propValue), "prop_value", propValue);
		String skuId = (String) params.get("skuId");
        queryWrapper.eq(ToolUtil.isNotEmpty(skuId), "sku_id", skuId);
		Page<ItemSkuPropEntity> page = itemSkuPropMapper.selectPage(new Query<ItemSkuPropEntity>(params).getPage(), queryWrapper);
		return new PageUtil(page);
    }

	/**
	 * 自定义分页查询，含关联实体对像
	 */
	public PageUtil findPage(Map<String, Object> params,ItemSkuPropEntity itemSkuPropEntity) {
		Page<ItemSkuPropEntity> page = itemSkuPropMapper.findPage(new Query<ItemSkuPropEntity>(params).getPage(),
					itemSkuPropEntity,
				(String) params.get(Constant.SQL_FILTER));
		return new PageUtil(page);
	}

	/**
	* 查列表
	*/
	public List<ItemSkuPropEntity> findList(ItemSkuPropEntity itemSkuPropEntity){
		return itemSkuPropMapper.findList(itemSkuPropEntity);
	}

	/**
     * 批量删除
     */
	@Transactional(rollbackFor = Exception.class)
	public boolean deleteBatchByIds(Long[] ids) {
		return this.removeByIds(Arrays.asList(ids));
	}

	/**
     * 单个删除
     */
	@Transactional(rollbackFor = Exception.class)
	public boolean delItemSkuPropById(Long pkId) {
		return this.removeById(pkId);
	}

	/**
     * 保存
     */
	@Transactional(rollbackFor = Exception.class)
	public boolean addItemSkuProp(ItemSkuPropEntity itemSkuProp){
		if(this.save(itemSkuProp)){
			return true;
		}
        return false;
    }

	/**
     * 修改根居ID
     */
	@Transactional(rollbackFor = Exception.class)
	public boolean updateItemSkuPropById(ItemSkuPropEntity itemSkuProp) {
		if(this.updateById(itemSkuProp)){
			return true;
		}
		return false;
	}

	/**
     * 根居ID获取对象
     */
	public ItemSkuPropEntity findItemSkuPropById(Long pkId){
		return itemSkuPropMapper.findItemSkuPropById(pkId);
	}


}
